<?php

/**
 * MVM_MALL 网上商店系统  投票管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-12-25 $
 * $Id: poll.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if($action=='list'){
    $result = $db->query("SELECT * FROM {$tablepre}poll_table  ORDER BY uid DESC");
    while ($rt = $db->fetch_array($result)) {
    	$rt['register_date'] = date($mm_date_format,$rt['register_date']);
    	$rt['start_date']    = date($mm_date_format,$rt['start_date']);
    	$rt['end_date']      = date($mm_date_format,$rt['end_date']);
    	$rt['edit']          = "admincp.php?module=$module&action=edit&uid=$rt[uid]";
		$rt['del']           = "admincp.php?module=$module&action=del&uid=$rt[uid]";
    	$rt_poll[]           = $rt;
    }
    require_once template('poll');
    footer();
} elseif ($action=='add') {
    if($setp==1&&$_POST){
        $start_date = time_format($start_date);
        $end_date   = time_format($end_date);
        $rows  = array(
                    'poll_question'   => $poll_question,
                    'poll_num'        => $poll_num,
                    'poll_answer1'    => $poll_answer1,
                    'poll_answer2'    => $poll_answer2,
                    'poll_answer3'    => $poll_answer3,
                    'poll_answer4'    => $poll_answer4,
                    'poll_answer5'    => $poll_answer5,
                    'poll_answer6'    => $poll_answer6,
                    'poll_answer7'    => $poll_answer7,
                    'poll_answer8'    => $poll_answer8,
                    'poll_answer9'    => $poll_answer9,
                    'poll_answer10'   => $poll_answer10,
                    'start_date'      => $start_date,
                    'end_date'        => $end_date,
                    'register_date'   => $m_now_time
                    );
        $db->insert("{$tablepre}poll_table",dhtmlchars($rows));
        $cache->put_cache('poll');
        admin_msg('success','admincp.php?module=poll&action=list');
    }else {
    	$rt_answer = array('1'=>'','2'=>'','3'=>'','4'=>'','5'=>'','6'=>'','7'=>'','8'=>'','9'=>'','10'=>'');
    	$num_select = drop_menu(array('0','1','2','3','4','5','6','7','8','9','10'),'poll_num');
        require_once template('poll_add');
        footer();
    }
} elseif ($action=='edit' && is_numeric($uid)) { 
    if($setp==1&&$_POST){
        $start_date = time_format($start_date);
        $end_date   = time_format($end_date);
        $rows  = array(
                    'poll_question'   => $poll_question,
                    'poll_num'        => $poll_num,
                    'poll_answer1'    => $poll_answer1,
                    'poll_answer2'    => $poll_answer2,
                    'poll_answer3'    => $poll_answer3,
                    'poll_answer4'    => $poll_answer4,
                    'poll_answer5'    => $poll_answer5,
                    'poll_answer6'    => $poll_answer6,
                    'poll_answer7'    => $poll_answer7,
                    'poll_answer8'    => $poll_answer8,
                    'poll_answer9'    => $poll_answer9,
                    'poll_answer10'   => $poll_answer10,
                    'start_date'      => $start_date,
                    'end_date'        => $end_date,
                    'register_date'   => $m_now_time
                    );
         $db->update("{$tablepre}poll_table",dhtmlchars($rows),"uid='$uid'");
        $cache->put_cache('poll');
        admin_msg('success','admincp.php?module=poll&action=list');           
    }else {
       $rt = $db->get_one("SELECT * FROM {$tablepre}poll_table WHERE uid = '$uid'");
       @extract($rt,EXTR_OVERWRITE);
       $start_date = date('Y-m-d',$start_date);
       $end_date   = date('Y-m-d',$end_date);
       $num_select = drop_menu(array('0','1','2','3','4','5','6','7','8','9','10'),'poll_num',$poll_num);
       $rt_answer = array('1'=>$poll_answer1,'2'=>$poll_answer2,'3'=>$poll_answer3,'4'=>$poll_answer4,'5'=>$poll_answer5,'6'=>$poll_answer6,'7'=>$poll_answer7,'8'=>$poll_answer8,'9'=>$poll_answer9,'10'=>$poll_answer10);
       require_once template('poll_add');
       footer();
   }
}elseif ($action=='del' && is_numeric($uid)){
    $db->query("DELETE FROM {$tablepre}poll_table WHERE uid='$uid' ");
    $cache->put_cache('poll');
} else {
    admin_msg('pass_worng');
}